package com.lsh.oms.core.model.order;

import com.lsh.base.lang.json.Jsons;
import com.lsh.oms.core.model.base.VenderModel;
import com.lsh.oms.core.model.calService.CalShippingDetailVo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Map;

/**
 * @author peter
 */
@Getter
@Setter
@NoArgsConstructor
@ToString
public class OrderShippingDetail extends VenderModel implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -733725057162161988L;

    private Long id;

    private Long shippingOrderId;

    private Integer itemCode;

    private Long skuId;

    private String skuName;

    private Long itemId;

    private BigDecimal saleUnit;

    private BigDecimal qty;

    private BigDecimal realQty;

    private BigDecimal price;

    private BigDecimal money;

    private Integer status;

    private String ext;

    private Integer createdAt;

    private Integer updatedAt;

    private Integer zoneId;

    private Long packageId;

    private String code;

    private Long tmsId;

    private Integer supplierOrg;

    private Map<String, Object> extendedProperties;

    public Map<String, Object> getExtendedProperties() {
        if (extendedProperties == null) {
            extendedProperties = Jsons.fromJsonString(ext);
        }
        return extendedProperties;
    }

    public OrderShippingDetail(CalShippingDetailVo vo) {
        this.tmsId = 0L;
        this.skuId = Long.parseLong(vo.getSkuId());
        this.skuName = vo.getSkuName();
        this.saleUnit = vo.getSaleUnit();
        this.qty = new BigDecimal(vo.getQty());
        this.realQty = vo.getRealQty();
        this.price = new BigDecimal(vo.getPrice());
        this.money = new BigDecimal(vo.getMoney());
        this.status = 1;
        this.ext = "";
        this.packageId = Long.parseLong(vo.getPackageId());
    }


    public Boolean isWeighingGoods() {
        return Integer.valueOf(1).equals(getExtendedProperties().get("is_weighing_goods")) || "1".equals(getExtendedProperties().get("is_weighing_goods"));
    }
}